<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>签离</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">

		<!-- 	<link rel="stylesheet" href="../../../css/mui.picker.css">
		<link rel="stylesheet" href="../../../css/mui.poppicker.css"> -->


		<link href="../../../css/task.css" rel="stylesheet" />
		<style type="text/css">
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}

			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}

			#div1 {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}

			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover1 .mui-popover-arrow:after {
				width: 0px;
			}

			#div2 {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}

			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover2 .mui-popover-arrow:after {
				width: 0px;
			}
			
			#div6 {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}
			
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover6 .mui-popover-arrow:after {
				width: 0px;
			}

			.details_con {
				background: #fff;
			}
			.mui-btn-block {
				border: 0;
				font-size: 16px;
				color: #a9a9a9;
			}
			.selectDate{
				background: url(../../../images/icon_32.png) no-repeat right center !important;
				background-size: 14px 13px !important;
				color: #8E8E93 !important;
			}
			.popover .my-content-cell {
				padding: 0;
				margin: 0 10px;
			}
			.popover .arrow-right-position {
				right: -5px;
			}
			input.d_ipt {
				width: 60%;
			}
		</style>
	</head>

	<body>
		<div id="div"></div>
		<div id="popover" class="mui-popover shadow popover">
			<p class="title">请确定服务是否全部完成?</p>
			<div class="btn_box">
				
				<span class="fl" id="noTrue">未完成</span>
				<span class="fr red" id="btnYes">已完成</span>
			</div>
		</div>

		<div id="div1"></div>
		<div id="popover1" class="mui-popover shadow popover">
			<div class="details_con">
				<div class="my-content-cell">
					<div class="inline-block" id="pjcgqd">
						<em>查看计划安排</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="clum" style="margin: 0 10px;">
					<span class="name">预计上门时间<em class="t_red">*</em></span>
					<button id='estimatedVisitingTime' type="button" class="selectDate">请选择时间</button>
				</div>
				<div class="clum" style="margin: 0 10px;">
					<span class="name">预计工时<em class="t_red">*</em></span>
					<input id="estimatedWorkingHours" type="number" class="d_ipt" placeholder="请输入预计工时" onchange="jisuan('1')" />
				</div>
				<div class="clum" style="margin: 0 10px;">
					<span class="name">预计离开时间<em class="t_red">*</em></span>
					<input id="estimatedDepartureTime" type="text" class="d_ipt" placeholder="自动计算" disabled="disabled" />
				</div>
			</div>

			<div class="btn_box">
				
				<span class="fl" id="closeDoor" onclick="closeDoor()">取消</span>
				<span class="fr red" id="saveDoor">确定</span>
			</div>
		</div>

		<div id="div2"></div>
		<div id="popover2" class="mui-popover shadow popover">
			<p class="title">你当前处于休假状态，不能签离，是否立即结束休假？</p>
			<div class="btn_box">
				
				<span class="fl" onclick="closepop2()">取消</span>
				<span class="fr red" id="quedingupdate">确定</span>
			</div>
		</div>
		
		<div id="div6"></div>
		<div id="popover6" class="mui-popover shadow popover">
			<p class="title" id="title">与您之前的工作计划时间冲突，是否确定？</p>
			<div class="btn_box">
				
				<span class="fl" onclick="closepop6()">取消</span>
				<span class="fr red" id="quedingupdate6">确定</span>
			</div> 
		</div>

		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">签离</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div class="clum">
					<span class="name">服务编号</span>
					<span class="txt" id="serviceNo"></span>
				</div>
				<div class="clum">
					<span class="name">提交时间</span>
					<span class="txt" id="createTime"></span>
				</div>
				<div class="clum">
					<span class="name">服务子类型</span>
					<span class="txt" id="serviceType"></span>
				</div>
				<div class="clum_arr">
					<span class="name_arr">客户名称</span>
					<span class="txt_arr" id="customerName"></span>
				</div>
				<div class="clum">
					<span class="name">客户类型</span>
					<span class="txt" id="enginnerType"></span>
				</div>
				<div class="clum">
					<span class="name">期望服务时间</span>
					<span class="txt" id="hopeBusinessHours"></span>
				</div>
				<div class="clum">
					<span class="name">服务角色</span>
					<span class="txt">
						<input class="serviceRole" name="serviceRole" type="radio" value="1" disabled="disabled">现场服务&nbsp;&nbsp;
						<input class="serviceRole" name="serviceRole" type="radio" value="2" disabled="disabled">实习
					</span>
				</div>
				<div class="line"></div>
				<div class="my-content-cell">
					<div class="inline-block" id="khxxxx">
						<em>客户详细信息</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="yqxx">
						<em>仪器详细信息</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="htxx">
						<em>合同详细信息</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="fwtzxx">
						<em>服务通知详细信息</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="tjsybjxx">
						<em>推荐使用备件详细信息</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="xxggsq">
						<em>信息更改申请</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="ckbg">
						<em>查看报告</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="ckrz">
						<em>查看日志</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
				<div class="my-content-cell">
					<div class="inline-block" id="report">
						<em>Error Report&Hot Account Report</em>
						<span class="mui-icon mui-icon-arrowright arrow-right-position"></span>
					</div>
				</div>
			</div>
			<div class="btn_box">
				
				<span class="fl" id="zzrz">工作日志</span>
				<span class="fr red" id="ql">签离</span>
			</div>
			<div style="height: 50px;"></div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/sqliteTools.js"></script>
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script type="text/javascript" charset="utf-8">
			var ServiceNoticeId
			var serviceNo
			var planId

			// 仪器详情用带过去
			var trainQuota
			var installationDate
			var cfda

			// 服务通知详细信息用
			var serviceType
			var isWarranty
			var troubleDescription
			var remark
			var serviceRole
			var longitude
			var latitude
			var noticeId
			var signInTime
			
			var estimatedVisitingTime
			var estimatedWorkingHours
			var estimatedDepartureTime
			
			// report用
			var divBu
			var problem
			
			var btnYes

			// 取消方法 关闭弹窗
			function closepop2() {
				mui("#popover2").popover('hide', document.getElementById("div2"));
			}
			
			function closepop6(){
				mui("#popover6").popover('hide', document.getElementById("div6"));
			}

			(function($, doc) {
				$.init();

				new Rolldate({
					el: '#estimatedVisitingTime',
					format: 'YYYY-MM-DD hh:mm',
					beginYear: 2015,
					endYear: 2050,
					trigger: 'click',
					lang: {
						title: '请选择预计上门时间',
					},
					confirm: function(date) {
						jisuan(date)
					}
				})


				$.plusReady(function() {

					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					// 获取上一个页面传过来的参数并显示到页面
					ServiceNoticeId = self.ServiceNoticeId;
					serviceNo = self.serviceNo;
					planId = self.planId;
					
					// 20200521 调接口（查询已关联服务报告的日志）判断是否显示工作日志按钮  (最终不需添加此校验！)
					// selectBoundList(serviceNo);

					// 获取定位的经纬度
					app.showWaiting('加载中...')
					plus.geolocation.getCurrentPosition(function(p) {
						longitude = p.coords.longitude;
						latitude = p.coords.latitude;
						
						//获取签到时间
						findSignInTime();
						// 获取详情的方法
						getDetails();
					}, function(e) {
						app.closeWaiting();
						app.toast("定位失败");
					}, {geocode: false});
				
					// 查看计划安排
					h("#pjcgqd").tap(function() {
						app.jumpTo("/view/service/taskDetails/task_details.html", "view/service/taskDetails/task_details.html",
							{
								serviceNoticeId: ServiceNoticeId,
								serviceNo: serviceNo,
								enginnerId: app.getUser().enginnerId
							}
						);
					});

					// 客户详细信息
					h("#khxxxx").tap(function() {
						app.jumpTo("/view/service/accept/customerDetails.html", "view/service/accept/customerDetails.html", {
							ServiceNoticeId: ServiceNoticeId,
							serviceNo: serviceNo,
							planId: planId
						});
					})

					// 合同详细信息
					h("#htxx").tap(function() {
						// app.toast("暂未开放");
						app.jumpTo("/view/service/accept/contractDetails.html", "view/service/accept/contractDetails.html",{
							serviceNo: serviceNo,
						});
					})

					// 仪器详细信息
					h("#yqxx").tap(function() {
						app.jumpTo("/view/service/accept/instrumentDetails.html", "view/service/accept/instrumentDetails.html", {
							ServiceNoticeId: ServiceNoticeId,
							serviceNo: serviceNo,
							planId: planId,
							trainQuota: trainQuota,
							installationDate: installationDate,
							cfda: cfda
						});
					})

					// 服务通知详细信息
					h("#fwtzxx").tap(function() {
						app.jumpTo("/view/service/accept/noticeDetails.html", "view/service/accept/noticeDetails.html", {
							ServiceNoticeId: ServiceNoticeId,
							serviceNo: serviceNo,
							planId: planId,
							serviceType: serviceType,
							isWarranty: isWarranty,
							troubleDescription: troubleDescription,
							remark: remark
						});
					})

					// 推荐使用备件详细信息
					h("#tjsybjxx").tap(function() {
						app.jumpTo("/view/service/accept/partDetails.html", "view/service/accept/partDetails.html", {
							ServiceNoticeId: ServiceNoticeId,
							serviceNo: serviceNo,
							planId: planId
						});
					})

					// 信息更改申请
					h("#xxggsq").tap(function() {
						app.jumpTo("/view/service/accept/infoUpdate.html", "view/service/accept/infoUpdate.html", {
							ServiceNoticeId: ServiceNoticeId,
							serviceNo: serviceNo,
							noticeId: ServiceNoticeId,
							planId: planId
						});
					})

					// 查看日志
					h("#ckrz").tap(function() {
						app.jumpTo("/view/service/serviceLog/noticeLogList.html", "view/service/serviceLog/noticeLogList.html", {
							serviceNo: serviceNo,
							planId: planId
						});
					})
					// 查看报告
					h("#ckbg").tap(function() {
						app.jumpTo("/view/service/report/work/workReportList.html", "view/service/report/work/workReportList.html", {
							serviceNo: serviceNo
						});
					})
					// Error Report&Hot Account Report
					h("#report").tap(function() {
						app.jumpTo("/view/service/report/errorhot/erroOrHot.html", "view/service/report/errorhot/erroOrHot.html", {
							serviceNo: serviceNo,
							serviceType: serviceType,
							planId: planId,
							noticeId: ServiceNoticeId,
							divBu: divBu,
							problem: problem
						});
					})

					// 确定完成全部服务  签离操作
					h("#btnYes").tap(function() {
						btnYes();
					});
					btnYes = function () {
						app.showWaiting('正在提交...')
						ajaxGet(BASE_URL + "cc/PlanDetails/fseSignOff", {
							"ServiceNoticeId": ServiceNoticeId,
							"serviceNo": serviceNo,
							"EnginnerId": app.getUser().enginnerId,
							"customerName": h("#customerName").html(),
							"signInTime": signInTime,
							"longitude": longitude,
							"latitude": latitude,
							"state": 4
						}, function(data) {
							mui("#popover").popover('hide', document.getElementById("div"));
							app.closeWaiting()
							if (data.code == 200) {	
								if(data.data && data.data.length > 0){
									// 判断是否存在离线数据，
									var enginnerId = app.getUser().enginnerId;
									var sqliteTool = new sqliteTools(); 
									sqliteTool.openDatabase();
									for (var i = 0; i < data.data.length; i++) {
										var resData = data.data[i];					
										sqliteTool.selectServiceByPlanId(enginnerId, resData.planId, resData, function(flag, offlineData, callBackData) {
											if (offlineData && offlineData.length > 0) {
												sqliteTool.deleteServiceData(offlineData.planId, function(flag) {
													console.log("删除本地数据"+flag)
												})
											}									
										});
									}
									setTimeout(function() {
										sqliteTool.closeDB();
										app.toast('操作成功')
										// 处理页面跳转
										tiaozhuan('wancheng')
									}, 500);
								} else {
									app.toast('操作成功')
									// 处理页面跳转
									tiaozhuan('wancheng')
								}		
							} else {
								app.toast('操作失败')
							}
						}, function(errorMsg) {
							app.closeWaiting()
							app.toast('操作失败')
							console.log(JSON.stringify(errorMsg))
						});
						
					}
					
					h("#saveDoor").tap(function() {
						app.showWaiting('正在提交...')
						// 调用计算方法
						jisuan('1');
						estimatedVisitingTime = h("#estimatedVisitingTime").html();
						if (estimatedVisitingTime == null || estimatedVisitingTime == "" || estimatedVisitingTime == "请选择时间") {
							app.closeWaiting()
							app.toast("请选择预计上门时间");
							return
						}
						estimatedWorkingHours = h("#estimatedWorkingHours").val();
						if (estimatedWorkingHours == null || estimatedWorkingHours == "") {
							app.closeWaiting()
							app.toast("请输入预计工时");
							return
						}
						estimatedDepartureTime = h("#estimatedDepartureTime").val();

						var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
						var newDate = new Date().getTime();
						if(evt <= newDate){
							app.closeWaiting()
							app.toast("预计上门时间不可以小于当前时间");
							return
						}

						ajaxGet(BASE_URL + "cc/PlanDetails/checkPlanDetailsList", {
							"enginnerId": app.getUser().enginnerId,
							"estimatedVisitingTime": estimatedVisitingTime,
							"estimatedDepartureTime": estimatedDepartureTime,
							"planId": planId
						}, function(data) {
							 //console.log(JSON.stringify(data))
							 
							 if(data.code==200){
								saveIn()
							 }else{
								 app.closeWaiting()
								 mui("#popover6").popover('toggle', document.getElementById("div6"));
							 }
						}, function(errorMsg) {
							app.closeWaiting()
							app.toast(errorMsg)
							console.log(JSON.stringify(errorMsg))
						});
						
					});

					h("#quedingupdate6").tap(function(){
						 app.showWaiting('正在提交...')
						 saveIn()
					})
					

				});

				// 取消操作
				h("#noTrue").tap(function() {
					mui("#popover").popover('hide', document.getElementById("div"));
					setTimeout(function () {
						mui("#popover1").popover('toggle', document.getElementById("div1"));
					},200)
				});

				// 获取详情的方法
				function getDetails() {
					ajaxGet(BASE_URL + "cc/notice/getMyServiceNoticeDetail", {
						"ServiceNoticeId": ServiceNoticeId,
						"EnginnerId": app.getUser().enginnerId
					}, function(data) {
						app.closeWaiting()
						if (data.code == 200) {
							if (data.data && data.data.length > 0) {
								h("#serviceNo").html(data.data[0].serviceNo);
								h("#createTime").html(data.data[0].createTime);
								h("#serviceType").html(data.data[0].subServiceType);
								noticeId = data.data[0].id;
								divBu = data.data[0].divBu;
								problem = data.data[0].troubleDescription;
								h("#customerName").html(data.data[0].customerName);
								if (data.data[0].enginnerType == undefined || data.data[0].enginnerType == "") {
									h("#enginnerType").html("无");
								} else {
									h("#enginnerType").html(data.data[0].enginnerType);
								}
								if (data.data[0].hopeBusinessHours == undefined || data.data[0].hopeBusinessHours == "") {
									h("#hopeBusinessHours").html("无");
								} else {
									h("#hopeBusinessHours").html(data.data[0].hopeBusinessHours);
								}

								// 仪器详细信息页面用
								if (data.data[0].trainQuota == undefined || data.data[0].trainQuota == "") {
									trainQuota = "";
								} else {
									trainQuota = data.data[0].trainQuota;
								}
								if (data.data[0].installationDate == undefined || data.data[0].installationDate == "") {
									installationDate = "";
								} else {
									installationDate = data.data[0].installationDate;
								}
								if (data.data[0].cfda == undefined || data.data[0].cfda == "") {
									cfda = "";
								} else {
									cfda = data.data[0].cfda;
								}

								// 服务通知详细信息页面用
								if (data.data[0].serviceType == undefined || data.data[0].serviceType == "") {
									serviceType = "";
								} else {
									serviceType = data.data[0].serviceType;
								}
								if (data.data[0].isWarranty == undefined || data.data[0].isWarranty == "") {
									isWarranty = "";
								} else {
									isWarranty = data.data[0].isWarranty;
								}
								if (data.data[0].troubleDescription == undefined || data.data[0].troubleDescription == "") {
									troubleDescription = "";
								} else {
									troubleDescription = data.data[0].troubleDescription;
								}
								if (data.data[0].remark == undefined || data.data[0].remark == "") {
									remark = "";
								} else {
									remark = data.data[0].remark;
								}

								serviceRole = data.data[0].serviceRole
								if (serviceRole) {
									document.querySelector(`input[name='serviceRole'][value='${serviceRole}']`).checked = true;
								}
							}

						} else {
							app.toast(data.msg)
						}
					}, function(errorMsg) {
						app.closeWaiting()
						app.toast(errorMsg)
					});
				}

				// 签离
				h("#ql").tap(function() {
					app.showWaiting('正在提交...')
					ajaxGet(BASE_URL + "cc/user/checkUserWorkDay", {
						"enginnerId": app.getUser().enginnerId
					}, function(data) {
						if (data.code == 200) { //查询成功
							var xiujia = data.data[0].workday ? data.data[0].workday : "";
							if (xiujia == "3") {
								app.closeWaiting()
								mui("#popover2").popover('toggle', document.getElementById("div2"));
							} else {
								checkReport();
							}
						} else {
							app.closeWaiting()
							app.toast(data.msg)
						}
					}, function(errorMsg) {
						app.closeWaiting()
						console.log(JSON.stringify(errorMsg))
					});
				})

				// 弹窗确定按钮操作 
				h("#quedingupdate").tap(function() {
					app.showWaiting('正在提交...')
					ajaxGet(BASE_URL + "cc/user/updateUserWorkday", {
						"enginnerId": app.getUser().enginnerId,
						"workday": "1"
					}, function(data) {
						mui("#popover2").popover('toggle', document.getElementById("div2"));
						if (data.code == 200) { //查询成功
							checkReport();
						} else {
							app.closeWaiting()
							app.toast(data.msg);
						}
					}, function(errorMsg) {
						app.closeWaiting()
						console.log(JSON.stringify(errorMsg))
					});
				})

				// 工作日志
				h("#zzrz").tap(function() {
					app.jumpTo("/view/service/serviceLog/logAdd.html", "view/service/serviceLog/logAdd.html", {
						serviceNo: serviceNo,
						planId: planId,
						serviceNoticeId: ServiceNoticeId,
						listName: 'signOut'
					});
				})


			}(mui, document));

			// 取消方法 关闭弹窗
			function closepop() {
				mui("#popover").popover('hide', document.getElementById("div"));
			}
			// 取消方法 关闭弹窗
			function closeDoor() {
				mui("#popover").popover('hide', document.getElementById("div"));
				mui("#popover1").popover('hide', document.getElementById("div1"));
			}
			
			function checkReport(){
				//判断是否有关联的服务通知需要批量签离
				ajaxGet(BASE_URL + "cc/notice/AssociatedCustomers", {
					"ServiceNoticeId": ServiceNoticeId,
					"EnginnerId": app.getUser().enginnerId,
					"state": 2,
					// "planId": planId
				}, function(data) {
					if(data.code==200){
						if(data.data && data.data.length > 1){
							// 查询是否有已提交并且服务状态为未完成的服务报告
							ajaxGet(BASE_URL + "cc/notice/associatedCustomerSrelevanceByReport", {
								"ServiceNoticeId": ServiceNoticeId,
								"EnginnerId": app.getUser().enginnerId,
								"signInTime": signInTime,
								"state": 2,							
							}, function(data) {
								app.closeWaiting()
								if (data.code === 200) {
									if (data.data && data.data.length > 0 && data.data[0].finished == "1") {
										mui("#popover").popover('toggle', document.getElementById("div"));									
									} else {
										btnYes();
									}
								} else {
									app.toast(data.msg)
								}
							}, function(errorMsg) {
								app.closeWaiting()
								app.toast(errorMsg)
							});
						} else {
							// 20200526 修复226 1172514，填写了已完成的报告后，签离时不应再提示是否完成全部服务，默认应是“已完成”。见“参考-页面跳转-4.6备注”
							// 查询是否有已提交并且服务状态为已完成的服务报告
							ajaxGet(BASE_URL + "cc/report/info/checkReportResult", {
								"serviceNo": serviceNo
							}, function(data) {
								app.closeWaiting()
								if (data.code === 200) {
									if (data.data && data.data.length > 0) {
										btnYes()
									} else {
										mui("#popover").popover('toggle', document.getElementById("div"));
									}
								} else {
									app.toast(data.msg)
								}
							}, function(errorMsg) {
								app.closeWaiting()
								app.toast(errorMsg)
							});
						}
					}else{
						app.closeWaiting();
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting();
					app.toast(errorMsg)
				});
			}

			// 自动计算方法
			function jisuan(date) {
				var estimatedVisitingTime;
				if (date != "1") {
					estimatedVisitingTime = date
				} else {
					estimatedVisitingTime = h("#estimatedVisitingTime").html();
				}
				if (estimatedVisitingTime == null || estimatedVisitingTime == "" || estimatedVisitingTime == "请选择时间") {
					return
				}
				var evt = stringYYYYMMDDHHMMToDate(estimatedVisitingTime).getTime();
				var estimatedWorkingHours = h("#estimatedWorkingHours").val();
				if (estimatedWorkingHours == null || estimatedWorkingHours == "") {
					return
				}
				var edt = evt + estimatedWorkingHours * 60 * 60 * 1000;
				var estimatedDepartureTime = new Date(edt).Format("yyyy-MM-dd HH:mm");
				h("#estimatedDepartureTime").val(estimatedDepartureTime);
			}

			function findSignInTime() {
				//根据planId 获取签到时间
				ajaxGet(BASE_URL + "cc/PlanDetails/getDetailsById", {
					"id": planId
				}, function(data) {
					if (data.code == 200) {
						signInTime = data.data.signInTime
					} else {
						app.toast('查询失败');
					}
				}, function(errorMsg) {
					app.toast('查询失败');
					console.log(JSON.stringify(errorMsg))
				});
			}
			
			function saveIn(){
				ajaxGet(BASE_URL + "cc/PlanDetails/fseSignOffAgain", {
					"ServiceNoticeId": ServiceNoticeId,
					"serviceNo": serviceNo,
					"EnginnerId": app.getUser().enginnerId,
					"customerName": h("#customerName").html(),
					"signInTime": signInTime,
					"longitude": longitude,
					"latitude": latitude,
					"state": 3,
					"estimatedVisitingTime": estimatedVisitingTime,
					"estimatedWorkingHours": estimatedWorkingHours,
					"estimatedDepartureTime": estimatedDepartureTime
				}, function(data) {
					app.closeWaiting();
					if (data.code == 200) {
						if(data.data && data.data.length > 0){
							// 判断是否存在离线数据，
							var enginnerId = app.getUser().enginnerId;
							var fseName = app.getUser().name;
							var customerName = h("#customerName").html();
							var sqliteTool = new sqliteTools(); 
							sqliteTool.openDatabase();
							for (var i = 0; i < data.data.length; i++) {
								var resData = data.data[i];							
								sqliteTool.selectServiceByNoticeId(enginnerId, resData.serviceNoticeId, resData, function(flag, offlineData, callBackData) {
									if(flag){
										if (offlineData && offlineData.length > 0) {
											if(callBackData.state == "4"){
												sqliteTool.deleteServiceData(offlineData[0].planId, function(flag) {
													console.log("删除本地数据"+flag)
												})
											} else {
												sqliteTool.insertServiceSignOffAginData(offlineData[0].id, callBackData.planId, function(flag) {
													console.log("更新计划数据"+flag)
												})
											}
										} else {
											sqliteTool.insertServiceBaseData(callBackData.serviceNo, callBackData.serviceNoticeId, callBackData.planId, customerName, callBackData.instrumentId, callBackData.instSn, callBackData.acceptTime, enginnerId, fseName, callBackData.serviceType, callBackData.subServiceType, function (flag) {
												console.log("插入计划数据"+flag)
											})
										}
									}	
								});
							}
							setTimeout(function() {
								sqliteTool.closeDB();
								app.toast('操作成功')
								// 处理页面跳转
								tiaozhuan('qianli')
							}, 500);															
						} else {
							app.toast('操作成功')
							// 处理页面跳转
							tiaozhuan('qianli')
						}		
					} else {
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					app.toast('操作失败')
					console.log(JSON.stringify(errorMsg))
				});
			}

			function tiaozhuan(state) {
				// 关闭进行中
				var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
				if (conductList) {
					conductList.close()
				}
				
				// 关闭工作台查询未关闭服务通知列表
				var notClosedList = plus.webview.getWebviewById('view/service/notice/notClosedList.html');
				if(notClosedList){
					notClosedList.close()
				}
				
				// 刷新TL首页
				var indexTl=plus.webview.getWebviewById('view/main/indexTL.html');
				if(indexTl){
				    indexTl.evalJS('getMyTeamCount()')
				}
				
				// 1、刷新FSE首页
				var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
				if (indexFSE) {
					indexFSE.evalJS('getList("1")')
				}
				// 关闭工作台已签到列表
				var checkedInList = plus.webview.getWebviewById('view/service/notice/checkedInList.html');
				if (checkedInList) {
					checkedInList.close()
				}
				// 关闭核对序列号页面
				var checkInstrument = plus.webview.getWebviewById('view/service/checkInstrument/checkInstrument.html');
				if (checkInstrument) {
					checkInstrument.close()
				}
				
				// 关闭工作台已签离列表
				// var checkedOutList = plus.webview.getWebviewById('view/service/notice/checkedOutList.html');
				// if (checkedOutList) {
				// 	checkedOutList.close()
				// }
				var self = plus.webview.currentWebview();
				if(state=='qianli'){
					// 5、已签离
					var checkedOutList = plus.webview.getWebviewById('view/service/notice/checkedOutList.html');
					if(checkedOutList){
						var signOutVisitAgain = plus.webview.getWebviewById('view/service/notice/signOutVisitAgain.html');
						if (signOutVisitAgain) {
							signOutVisitAgain.close()
						}
						checkedOutList.evalJS('getList()')
						self.close();
						mui.back();
					}else{
						var checkedOutList1 = plus.webview.create('/view/service/notice/checkedOutList.html','view/service/notice/checkedOutList.html')
						checkedOutList1.show()
						self.close()
					}

				}else{
					var completedList = plus.webview.getWebviewById('view/service/notice/completedList.html');
					if (completedList) {
						var signOutVisitAgain = plus.webview.getWebviewById('view/service/notice/signOutVisitAgain.html');
						if (signOutVisitAgain) {
							signOutVisitAgain.close()
						}
						completedList.evalJS('initData()')
						self.close();
						mui.back();
					} else {
						var completedList1 = plus.webview.create('/view/service/notice/completedList.html',
							'view/service/notice/completedList.html')
						completedList1.show()
						self.close();
					}
					
				}
				
			}
			
			// 查询未完成状态下 已关联服务报告的日志, 有则隐藏
			function selectBoundList(serviceNo) {
				ajaxPost(BASE_URL + "cc/ServiceLog/selectBoundList", { 
					"serviceNo": serviceNo,
					"fseId": app.getUser().enginnerId,
				}, function(data) {
					// if (null != data.data && data.data.length > 0) {
					// 	h("#zzrz").hide()
					// } else {
					// 	h("#zzrz").show()
					// }
				}, function(errorMsg) {
				});
			}
		</script>
		<!-- js代码 end -->

	</body>

</html>
